﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}

<!DOCTYPE html>


<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>生产报工</title>
    <link href="~/lib/layui/css/layui.css" rel="stylesheet" />
    @* <script src="~/lib/layui/layui.js"></script> *@
    <script src="~/js/js.cookie.js"></script>
    <script src="~/js/moment.js"></script>
    <script src="~/lib/jquery/dist/jquery.js"></script>
</head>
<body>
    <form class="layui-form" action="">
        <div class="layui-form">
            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div class="layui-input-prefix" style="left:43px">
                        报工类型
                    </div>
                    <div style="left:42px">
                        <div>
                            <select id="productionTypeId" lay-filter="testSelect">
                                <option value="-1">请选择报工类型</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-input-prefix" style="left:60px">
                        工作站名称
                    </div>
                    <div style="left:60px">
                        <input id="workStationName" type="text" placeholder="请输入工作站名称" class="layui-input">
                    </div>

                    <div class="layui-input-prefix" style="left:80px">
                        生产工单号
                    </div>
                    <div style="left:80px">
                        <input id="productionWorkOrdersNo" type="text" placeholder="请输入生产工单号" class="layui-input">
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div class="layui-input-prefix" style="left:14px">
                        产品物料编码
                    </div>
                    <dic style="left:14px">
                        <input style="width:213px" id="productManageNode" type="text" placeholder="请输入产品物料编码" class="layui-input">
                    </dic>

                    <div class="layui-input-prefix" style="left:17px">
                        产品物料名称
                    </div>
                    <div style="left:17px;width:197px">
                        <input id="productManageName" type="text" placeholder="请输入产品物料名称" class="layui-input">
                    </div>

                    <div class="layui-input-prefix" style="left:65px">
                        报工人
                    </div>
                    <dic style="left:65px">
                        <input style="width:198px" id="departmentName" type="text" placeholder="请输入报工人" class="layui-input">
                    </dic>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div class="layui-input-prefix" style="left:56px">
                        记录人
                    </div>
                    <dic style="left:56px">
                        <input style="width:198px" id="departmentName" type="text" placeholder="请输入记录人" class="layui-input">
                    </dic>

                    <div class="layui-input-prefix" style="left:130px">
                        状态
                    </div>
                    <div style="left:130px;width:197px">
                        <select id="sellStockStart" lay-filter="testSelect">
                            <option value="-1">请选择状态</option>
                            <option value="0">草稿</option>
                            <option value="1">已确认</option>
                            <option value="2">审批中</option>
                            <option value="3">已审批</option>
                            <option value="4">已完成</option>
                        </select>
                    </div>

                    <div style="left:170px">
                        <button onclick="ProductionSearch(1,2)" id="searchBtn" type="button" class="layui-btn layui-btn-normal">搜索</button>
                    </div>

                    <div style="left:190px">
                        <button onclick="Break()" type="button" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-input-group">
                    <div>
                        <button type="button" class="layui-btn layui-btn-sm layui-btn-primary layui-border-blue" lay-on="test-page-custom">
                            <i class="layui-icon layui-icon-add-1">新增</i>
                        </button>
                        <button type="button" class="layui-btn demo-class-accept" lay-options="{accept: 'file'}">
                            <i class="layui-icon layui-icon-upload"></i>
                            上传文件
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <table style="left:320px" class="layui-hide" id="ID-table-demo-datas" lay-filter="ID-table-demo-datas"></table>
    <script type="text/html" id="toolDemos">
        <div class="layui-clear-space">
            <a style="color:cornflowerblue" lay-event="delect">删除 </a>

            <a class="btn btn-link layui-btn-xs" lay-on="test-page-customseer" lay-event="Update"  style="color:cornflowerblue">编辑 </a>

            <a lay-on="test-iframe-curs" lay-event="YesNo"  style="color:cornflowerblue">审批</a>
        </div>
    </script>
    <div id="demo-laypage-alles"></div>

    <script type="text/html" id="toolDemo">
        <div class="layui-clear-space">
            <a class="layui-btn layui-btn-xs" lay-event="YesWang">选择</a>
        </div>
    </script>
    <script src="//unpkg.com/layui@2.9.18/dist/layui.js"></script>

    <script>
        var $ = layui.$;
        var layer = layui.layer;
        var util = layui.util;
        var form = layui.form; 
        layui.use(function () {
            // 事件
            util.on('lay-on', {
                'test-page-customs': function () {
                    layer.open({
                        type: 1,
                        area: '100%',
                        resize: false,
                        shadeClose: true,
                        title: '工单选择',
                        content: `
                        <form class="layui-form layui-row layui-col-space16">
                            <div class="layui-col-xs4">
                                <div class="layui-input-group">
                                    <div class="layui-input-prefix"><b>工单编码:</b> </div>
                                    <input type="text" id="ProductionWorkOrdersNoSe" value="" placeholder="请输入工单编码" class="layui-input" lay-affix="clear">
                                </div>
                            </div>
                            <div class="layui-col-xs4">
                                <div class="layui-input-group">
                                    <div class="layui-input-prefix"><b>工单名称:</b> </div>
                                    <input type="text" id="ProductionWorkOrdersNameSe" placeholder="请输入工单名称" lay-affix="clear" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-col-xs3">
                                <div class="layui-input-group">
                                    <div class="layui-input-prefix"><b>来源单据:</b> </div>
                                    <div class="layui-input-inline">
                                        <input type="radio" lay-filter="demo-radio-filter" name="SourceSe" value="" title="全部" checked>
                                        <input type="radio" lay-filter="demo-radio-filter" name="SourceSe" value="客户订单" title="客户订单">
                                        <input type="radio" lay-filter="demo-radio-filter" name="SourceSe" value="库存备货" title="库存备货">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md4">
                                <div class="layui-input-group">
                                    <div class="layui-input-prefix"><b>产品编号:</b> </div>
                                    <input type="text" id="ProductsNoSe" placeholder="请输入产品编号" lay-affix="clear" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-col-md4">
                                <div class="layui-input-group">
                                    <div class="layui-input-prefix"><b>产品名称:</b> </div>
                                    <input type="text" id="ProductsNameSe" placeholder="请输入产品名称" lay-affix="clear" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-col-md4">
                                <div class="layui-input-group">
                                    <div class="layui-input-prefix"><b>客户编码:</b> </div>
                                    <input type="text" id="ClientNoSe" placeholder="请输入客户编码" lay-affix="clear" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-col-xs4">
                                <div class="layui-input-group">
                                    <div class="layui-input-prefix"><b>客户名称:</b> </div>
                                    <input type="text" id="ClientNameSe" placeholder="请输入客户名称" lay-affix="clear" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-col-xs4">
                                <div class="layui-input-group">
                                    <div class="layui-input-prefix"><b>工单类型:</b> </div>
                                    <div class="layui-input-inline">
                                        <select id="TicketsTypeSe" lay-filter="aihao">
                                            <option value=""></option>
                                            <option value="自产">自产</option>
                                            <option value="外协">外协</option>
                                            <option value="外购">外购</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-xs4">
                                <div class="layui-input-group">
                                    <div class="layui-input-prefix"><b>需求日期:</b> </div>
                                    <div class="layui-input-wrap">
                                        <div class="layui-input-prefix">
                                            <i class="layui-icon layui-icon-date"></i>
                                        </div>
                                        <input type="text" id="DemandDateSe" readonly placeholder="请选择需求日期" class="layui-input demo-table-search-date">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-btn-container layui-col-xs12">
                                <button class="layui-btn" lay-submit lay-filter="demo-table-searchs">查询</button>
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </form>
                        <table class="layui-hide" id="ID-table-demo-search" lay-filter="ID-table-demo-search"></table>
                        <div id="demo-laypage-alls"></div>
                        `,
                        success: function () {
                            $(function () {
                                getTable(1, 100);
                            })
                            //列表显示
                            function getTable(pageIndex, pageSize) {
                                let dataObj = {
                                    productionWorkOrdersNo: $("#ProductionWorkOrdersNoSe").val(),
                                    productionWorkOrdersName: $("#ProductionWorkOrdersNameSe").val(),
                                    source: $("[name='SourceSe']:checked").val(),
                                    productsNo: $("#ProductsNoSe").val(),
                                    productsName: $("#ProductsNameSe").val(),
                                    clientNo: $("#ClientNoSe").val(),
                                    clientName: $("#ClientNameSe").val(),
                                    ticketsType: $("#TicketsTypeSe").val(),
                                    demandDate: $("#DemandDateSe").val() || null,
                                    pageIndex: pageIndex,
                                    pageSize: pageSize
                                }
                                // 创建表格实例
                                var inst = table.render({
                                    elem: '#ID-table-demo-search',
                                    method: 'POST',
                                    contentType: 'application/json',
                                    toolbar: '#toolbarDemo',
                                    defaultToolbar: ['filter', 'exports', 'print', { // 右上角工具图标
                                        title: '提示',
                                        layEvent: 'LAYTABLE_TIPS',
                                        icon: 'layui-icon-tips',
                                        onClick: function (obj) { // 2.9.12+
                                            layer.alert('自定义工具栏图标按钮');
                                        }
                                    }],
                                    url: '@ViewBag.FoundationRead' + '/api/WorkOrders/PageProductionList', // 此处为静态模拟数据，实际使用时需换成真实接口
                                    where: dataObj,
                                    cols: [[
                                        { field: 'productionWorkOrdersNo', title: '工单编码', width: 120, sort: true, fixed: true },
                                        { field: 'productionWorkOrdersName', title: '工单名称', width: 120 },
                                        { field: 'ticketsType', title: '工单类型', width: 100 },
                                        { field: 'source', title: '工单来源', width: 100 },
                                        { field: 'orderNumber', title: '订单编号', width: 100 },
                                        { field: 'productManageNode', title: '产品编号', width: 100 },
                                        { field: 'productManageName', title: '产品名称', width: 100 },
                                        { field: 'productManageNumber', title: '规格型号', width: 100 },
                                        { field: 'unites', title: '单位', width: 80 },
                                        { field: 'ticketsNum', title: '工单数量', width: 100 },
                                        { field: 'adjustNum', title: '调整数量', width: 100 },
                                        { field: 'proNum', title: '以生产数量', width: 100 },
                                        { field: 'batchNo', title: '批次号', width: 100 },
                                        { field: 'clientNo', title: '客户编码', width: 100 },
                                        { field: 'clientName', title: '客户名称', width: 100 },
                                        { field: 'demandDate', title: '需求日期', width: 100 },
                                        { field: 'state', title: '单据状态', width: 100 },
                                        { fixed: 'right', title: '操作', width: 140, minWidth: 140, templet: '#toolDemo' }
                                    ]],
                                    page: false,
                                    height: 310,
                                    done: function (res) {
                                        var id = this.id;
                                        console.log(res);// 你可以在这里检查返回的数据结构是否符合预期
                                        // 触发单元格工具事件
                                        //分页数据
                                        laypage.render({
                                            elem: 'demo-laypage-alls', // 元素 id
                                            count: res.totalCount, // 数据总数
                                            curr: pageIndex,
                                            limit: pageSize,
                                            limits: [2, 3, 4],
                                            layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'], // 功能布局
                                            jump: function (obj, first) {
                                                if (!first) {
                                                    getTable(obj.curr, obj.limit);
                                                }
                                            }
                                        });
                                    }
                                });
                            }
                            table.on('tool(ID-table-demo-search)', function (obj) { // 双击 toolDouble
                                var data = obj.data; // 获得当前行数据
                                console.log(data)
                                if (obj.event === 'YesWang') {
                                    $("#productionWorkOrdersNos").val(data.productionWorkOrdersNo);
                                    $("#productManageNodes").val(data.productManageNode);
                                    $("#productManageNames").val(data.productManageName);
                                    $("#unites").val(data.unites);
                                    $("#productManageNumber").val(data.productManageNumber);
                                    localStorage.setItem("productionWorkOrdersID", data.productionWorkOrdersID);
                                    // 对弹层中的表单进行初始化渲染
                                    form.render();
                                    layer.close(layer.index); // 关闭弹层
                                }
                            });
                            // 搜索提交
                            form.on('submit(demo-table-searchs)', function (data) {
                                getTable(1, 2);

                                return false; // 阻止默认 form 跳转
                            });
                        }
                    });
                }
            })
        });
        //自动生成编码
        function nodeAlls() {
            var datec = new Date()
            var year = datec.getFullYear();
            var month = (datec.getMonth() + 1).toString().padStart(2, "0")
            var date = (datec.getDate() + 1).toString().padStart(2, "0")
            var hours = datec.getHours()
            var minute = (datec.getMinutes()).toString().padStart(2, "0")
            var seconds = (datec.getSeconds()).toString().padStart(2, "0")
            // var Encoding = "IF";
            var result = "IF" + year + month + date + hours + minute + seconds;
            console.log(result);
            $("[name='sellStockNo']").val(result);

            //重新渲染表单
            form.render();
        }
    </script>

    <script>
        var $ = layui.$;
        var layer = layui.layer;
        var util = layui.util;
        var form = layui.form;
        layui.use(function () {
            // 事件
            util.on('lay-on', {
                'test-page-customsclient': function () {
                    layer.open({
                        type: 1,
                        area: '100%',
                        resize: false,
                        shadeClose: true,
                        title: '工单选择',
                        content: `
                                <table class="layui-table" height: 315>
                                    <colgroup>
                                        <col width="150">
                                        <col width="150">
                                        <col width="150">
                                        <col width="150">
                                        <col width="150">
                                    </colgroup>
                                    <thead>
                                        <tr>
                                            <th>部门编号</th>
                                            <th>企业全称</th>
                                            <th>部门名称</th>
                                            <th>部门类型</th>
                                            <th>区域</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody id="thisTd"></tbody>
                                </table>
                                <div id="demo-laypage-all"></div>
                                 `,
                        success: function () {
                            $(function () {
                                getPerList(pageIndex, pageSize);
                            })
                            var pageIndex = 1;
                            var pageSize = 2;
                            function getPerList(index, size) {
                                $.ajax({
                                    url: '@ViewBag.FoundationWrite' + "/api/Jocker/Departmentslist",
                                    type: "POST",
                                    data: JSON.stringify({ pageIndex: index, pageSize: size }),
                                    contentType: "application/json",
                                    success: function (res) {
                                        console.log(index, size);

                                        console.log(res.data);
                                        $("#thisTd").empty();
                                        $(res.data).each(function () {
                                            $("#thisTd").append(`<tr>
                                                    <td>${this.departmentNo}</td>
                                                    <td>${this.levelName}</td>
                                                    <td>${this.departmentName}</td>
                                                    <td>${this.typeName}</td>
                                                    <td>${this.areaName}</td>
                                                    <td><a onclick="GetClient('${this.departmentid}','${this.departmentName}')" class="btn btn-link">选择</a></td>
                                                    </tr>`)
                                        })
                                        var laypage = layui.laypage;
                                        // 完整显示
                                        laypage.render({
                                            elem: 'demo-laypage-all', // 元素 id
                                            count: res.totalCount, // 数据总数
                                            limit: size, // 每页显示的条数
                                            curr: index, // 当前页
                                            limits: [2, 3, 4],
                                            layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'], // 功能布局
                                            jump: function (obj, first) {
                                                // 首次不执行
                                                // 首次不执行
                                                if (!first) {
                                                    console.log(obj.curr);
                                                    console.log(obj.limit);
                                                    getPerList(obj.curr, obj.limit);
                                                }
                                            }
                                        });
                                    }
                                })
                            }
                        }
                    });
                }
            })
        });
        function GetClient(departmentid, departmentName) {
            localStorage.setItem("departmentid", departmentid);
            $("#departmentNames").val(departmentName);
            $("#departmentNamed").val(departmentName);
            console.log(departmentid, departmentName);
            layer.close(layer.index); // 关闭弹层
            form.render(); // 重新渲染
        }
    </script>

    <script>
        var $ = layui.$;
        var layer = layui.layer;
        var util = layui.util;
        var form = layui.form;
        layui.use(function () {
            // 事件
            util.on('lay-on', {
                'test-page-customsp': function () {
                    layer.open({
                        type: 1,
                        area: '100%',
                        resize: false,
                        shadeClose: true,
                        title: '生产任务选择',
                        content: `
                                <!-- 查询条件 -->
            <form class="layui-form" action="">
                <div class="layui-form">
                    <div class="layui-form-item">
                        <div class="layui-input-group">

                            <!-- 领料单编号 -->
                            <div class="layui-input-prefix">
                                <b>领料单编号</b>
                            </div>
                            <div>
                                <input id="pickingNode" type="text" placeholder="请输入领料单编号" class="layui-input" autocomplete="off" lay-affix="clear">
                            </div>

                            <!-- 领料单名称 -->
                            <div class="layui-input-prefix" tyle="left:50px">
                                <b>领料单名称</b>
                            </div>
                            <div>
                                <input id="pickingName" type="text" placeholder="请输入领料单名称" class="layui-input" autocomplete="off" lay-affix="clear">
                            </div>

                            <!-- 仓库名称 -->
                            <div class="layui-input-prefix" tyle="left:50px">
                                <b>仓库名称</b>
                            </div>
                            <div>
                                <input id="x" type="text" placeholder="请输入仓库名称" class="layui-input" autocomplete="off" lay-affix="clear">
                            </div>

                            <!-- 领料日期 -->
                            <div class="layui-input-prefix" tyle="left:50px">
                                <b>领料日期</b>
                            </div>
                            <div style="width:220px;left:43px">
                                <input style="width:210px" type="date" id="pickingTime" value="" placeholder="请输入领料日期" lay-reqtext="请填写领料日期" autocomplete="off" class="layui-input" lay-affix="clear">
                            </div>

                            <!-- 单据状态 -->
                            <div class="layui-input-prefix" style="left:50px">
                                <b>单据状态</b>
                            </div>
                            <div style="left:77px;width:197px">
                                <select id="documents" lay-filter="testSelect" autocomplete="off" lay-affix="clear">
                                    <option value="">请选择单据状态</option>
                                    <option value="1">草稿</option>
                                    <option value="2">已确认</option>
                                    <option value="3">审批中</option>
                                    <option value="4">已审批</option>
                                    <option value="5">已完成</option>
                                </select>
                            </div>

                            <!-- 按钮 -->
                            <div class="layui-btn-container layui-col-xs12">
                                <button class="layui-btn" lay-submit lay-filter="demo-table-search">查询</button>
        @*                          <button onclick="PickingLists()" id="searchBtn" type="button" class="layui-btn layui-btn-normal">搜索</button> *@
                                <button type="button" class="layui-btn layui-btn-primary">重置</button>
                            </div>



                        </div>
                    </div>
                </div>
            </form>
            <br />
            <div>
                <button onclick="Adds()" id="searchBtn" type="button" class="layui-btn layui-btn-normal layui-icon-addition">新增</button>
                <button type="button" class="layui-btn layui-icon-edit" layui-btn-green " >修改</button>
                <button type="button" class="layui-btn layui-bg-red layui-icon-delete">删除</button>
            </div>
            <!-- 表格 -->
            <div>
                <table class="layui-table">
                    <colgroup>
                        <col width="80">
                        <col width="130">
                        <col width="130">
                        <col width="130">
                        <col width="130">
                        <col width="130">
                        <col width="130">
                        <col width="130">
                        <col width="130">
                        <col width="130">
                        <col>
                    </colgroup>
                    <thead>
                        <tr>
                            <th style="text-align:center"><input type="checkbox" name="check" onclick="checkAll()" /></th>
                            <th style="text-align:center">领料单编号</th>
                            <th style="text-align:center">领料单名称</th>
                            <th style="text-align:center">生产工单</th>
                            <th style="text-align:center">工作站</th>
                            <th style="text-align:center">客户编号</th>
                            <th style="text-align:center">客户名称</th>
                            <th style="text-align:center">领料日期</th>
                            <th style="text-align:center">单据状态</th>
                            <th style="text-align:center">操作</th>
                        </tr>
                    </thead>
                    <tbody style="text-align:center">
                    </tbody>
                </table>
                <div id="demo-laypage-all"></div>
            </div>
                        `,
                        success: function () {
                            //分页
                            var pageIndex = 1;
                            var pageSize = 2;
                            var pickingNode = "";
                            var pickingName = "";
                            var pickingTime = null;
                            var documents = 0;

                            //就绪函数
                            $(function () {
                                PickingLists(pageIndex, pageSize); //生产领料 显示
                            })

                            // 搜索提交
                            form.on('submit(demo-table-search)', function (data) {
                                PickingLists(pageIndex, pageSize);
                                return false; // 阻止默认 form 跳转
                            });
                            //生产领料 显示
                            function PickingLists(pageIndex, pageSize) {
                                // console.log(info);
                                $.post({
                                    url: '@ViewBag.FoundationWrite' + '/api/ProductType/PickingsLists',
                                    data: JSON.stringify({
                                        pageIndex: pageIndex,
                                        pageSize: pageSize,
                                        pickingNode: $("#pickingNode").val() || "",
                                        pickingName: $("#pickingName").val() || "",
                                        pickingTime: $("#pickingTime").val() || null,
                                        documents: $("#documents").val() || 0,
                                    }),
                                    async: false,
                                    dataType: "json",
                                    contentType: "application/json",
                                    success: res => {
                                        console.log(res)

                                        var cont = ""; //定义变量
                                        $.each(res.data, function () {
                                            cont += `<tr>
                                    <td><input type="checkbox" class="check" value="${this.supplierId}" onclick="checkfan()"/></td>
                                    <td><span style="color:#1e9fff"><b>${this.pickingNode}</b></span></td>
                                    <td>${this.pickingName}</td>
                                    <td>${this.productionWorkOrdersNo}</td>
                                    <td>${this.workStationName}</td>
                                    <td>${this.clientNo}</td>
                                    <td>${this.clientName}</td>
                                    <td>${this.pickingTime.replace("T", " ").substring(0, 19)}</td>
                                    <td>${this.documents === 1 ? '草稿' : (this.documents === 2 ? '已确认' : (this.documents === 3 ? '审批中' : (this.documents === 4 ? '已审批' : '已完成')))}</td>
                                            <td><a onclick="GetSikping('${this.pickingNode}')" class="btn btn-link">选择</a></td>
                                </tr>`
                                        })
                                        $("tbody").html(cont);
                                        console.log(res);
                                        // console.log(996, pageSize, pageIndex, res)
                                        // 完整显示

                                        //完整显示
                                        laypage.render({
                                            elem: 'demo-laypage-all', // 元素 id
                                            count: res.totalCount, // 数据总数
                                            curr: pageIndex,//当前页
                                            limit: pageSize,//每页几条
                                            limits: [2, 3, 4],
                                            layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'], // 功能布局
                                            jump: function (obj, first) {
                                                if (!first) {
                                                    PickingLists(obj.curr, obj.limit);
                                                }
                                            }
                                        });
                                        // console.log(996, pickingNode, pickingName, pickingTime, documents,res);
                                        //  <a onclick="Updates(${this.pickingId})" class="btn btn-link layui-btn-xs" lay-on="test-page-customsed" style="color:green"">修改</a>
                                    }
                                });
                            };
                            PickingLists();
                        }
                    });
                }
            })
        });
        //自动生成编码
        function nodeAlls() {
            var datec = new Date()
            var year = datec.getFullYear();
            var month = (datec.getMonth() + 1).toString().padStart(2, "0")
            var date = (datec.getDate() + 1).toString().padStart(2, "0")
            var hours = datec.getHours()
            var minute = (datec.getMinutes()).toString().padStart(2, "0")
            var seconds = (datec.getSeconds()).toString().padStart(2, "0")
            // var Encoding = "IF";
            var result = "IF" + year + month + date + hours + minute + seconds;
            console.log(result);
            $("[name='sellStockNo']").val(result);

            //重新渲染表单
            form.render();
        }
        function GetSikping(pickingNode) {
            localStorage.setItem("pickingNode", pickingNode);
            $("#pickingNode").val(pickingNode);
            layer.close(layer.index); // 关闭弹层
            form.render(); // 重新渲染
        }
    </script>

    <script>
        var $ = layui.$;
        var layer = layui.layer;
        var util = layui.util;
        var form = layui.form;
        layui.use(function () {
            // 事件
            util.on('lay-on', {
                'test-page-custom': function () {
                    layer.open({
                        type: 1,
                        area: '100%',
                        resize: false,
                        shadeClose: true,
                        title: '添加生产报工记录',
                        content: `
                        <form class="layui-form" action="">
                            <div class="layui-form" lay-filter="filter-test-layer" style="margin: 16px;">
                            <div class="demo-Add-container">
                                <div class="layui-form-item">
                                    <div class="layui-input-group">
                                        <div class="layui-input-prefix" style="left:28px">
                                            报工类型
                                        </div>
                                        <div style="width:220px;left:28px">
                                            <select id="productionTypeIds" name="productionTypeName" >
                                                <option value="0">请选择报工类型</option>
                                            </select>
                                        </div>
                                        <div class="layui-input-prefix" style="left:70px">
                                            生产报工编号
                                        </div>
                                        <div style="width:220px;left:70px">
                                            <input style="width:220px" type="text" id="productionWorkNo" value="" lay-verify="required" placeholder="请输入生产报工编号" lay-reqtext="请填写生产报工编号" autocomplete="off" class="layui-input" lay-affix="clear">
                                        </div>
                                        <div style="left:70px">
                                            <button type="button" class="layui-btn layui-btn-primary layui-btn-xs" onclick="nodeAlls()">自动生成</button>
                                        </div>
                                        <div class="layui-input-prefix" style="left:110px">
                                            生产工单
                                        </div>
                                        <div style="width:220px;left:110px">
                                            <input style="width:220px" type="text" id="productionWorkOrdersNos" value="" lay-verify="required" placeholder="请输入生产工单" lay-reqtext="请填写生产工单" autocomplete="off" class="layui-input" lay-affix="clear">
                                        </div>
                                        <div style="left:110px">
                                            <button type="button" class="layui-btn layui-btn-primary" lay-on="test-page-customs">
                                                <i class="layui-icon layui-icon-search"></i>
                                            </button>
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-group">
                                        <div class="layui-input-prefix" style="left:28px">
                                            生产任务
                                        </div>
                                        <div style="width:220px;left:28px">
                                            <input style="width:220px" type="text" id="pickingNode" value="" lay-verify="required" placeholder="请输入生产任务" lay-reqtext="请填写生产任务" autocomplete="off" class="layui-input" lay-affix="clear">
                                        </div>
                                        <div style="left:28px">
                                            <button type="button" class="layui-btn layui-btn-primary" lay-on="test-page-customsp">
                                                <i class="layui-icon layui-icon-search"></i>
                                            </button>
                                        </div>
                                        <div class="layui-input-prefix" style="left:40px">
                                            产品编码
                                        </div>
                                        <div style="width:220px;left:40px">
                                            <input style="width:220px" type="text" id="productManageNodes" value="" lay-verify="required" placeholder="请输入产品编码" lay-reqtext="请填写产品编码" autocomplete="off" class="layui-input" lay-affix="clear">
                                        </div>
                                        <div class="layui-input-prefix" style="left:140px">
                                            产品名称
                                        </div>
                                        <div style="width:220px;left:140px">
                                            <input style="width:220px" type="text" id="productManageNames" value="" lay-verify="required" placeholder="请输入产品名称" lay-reqtext="请填写产品名称" autocomplete="off" class="layui-input" lay-affix="clear">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-group">
                                        <div class="layui-input-prefix" style="left:55px">
                                            单位
                                        </div>
                                        <div style="width:220px;left:55px">
                                            <input style="width:220px" type="text" id="unites" value="" lay-verify="required" placeholder="请输入单位" lay-reqtext="请填写单位" autocomplete="off" class="layui-input" lay-affix="clear">
                                        </div>

                                        <div class="layui-input-prefix" style="left:125px">
                                            规格型号
                                        </div>
                                        <div style="width:200px;left:125px">
                                            <div>
                                                <textarea style="width:500px" type="textarea" id="productManageNumber" value="" lay-verify="required" placeholder="请输入内容" lay-reqtext="请填写规格型号" autocomplete="off" class="layui-input layui-textarea" lay-affix="clear"></textarea>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-input-group">
                                        <div class="layui-input-prefix" style="left:26px">
                                            报工数量
                                        </div>
                                        <div style="width:220px;left:26px">
                                            <input style="width:220px" type="text" id="productionWorkNum" value="" lay-verify="required" placeholder="0" lay-reqtext="请填写报工数量" autocomplete="off" class="layui-input" lay-affix="clear">
                                        </div>
                                        <div class="layui-input-prefix" style="left:96px">
                                            待检数量
                                        </div>
                                        <div style="width:220px;left:96px">
                                            <input style="width:220px;" type="number" name="productionWorkNums" lay-affix="number" lay-filter="number" readonly placeholder="0" lay-reqtext="请填写待检数量" class="layui-input">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-group">
                                        <div class="layui-input-prefix" style="left:40px">
                                            报工人
                                        </div>
                                        <div style="width:220px;left:40px">
                                            <input style="width:220px" type="text" id="departmentNames" value="" lay-verify="required" placeholder="请输入报工人" lay-reqtext="请填写报工人" autocomplete="off" class="layui-input" lay-affix="clear">
                                        </div>
                                        <div style="left:40px">
                                            <button type="button" class="layui-btn layui-btn-primary" >
                                                <i class="layui-icon layui-icon-search" lay-on="test-page-customsclient"></i>
                                            </button>
                                        </div>
                                        <div class="layui-input-prefix" style="left:52px">
                                            报工时间
                                        </div>
                                        <div style="width:220px;left:52px">
                                            <input style="width:220px" type="date" id="productionWorkTime" value="" lay-verify="required" placeholder="请输入报工时间" lay-reqtext="请填写报工时间" autocomplete="off" class="layui-input" lay-affix="clear">
                                        </div>
                                        <div class="layui-input-prefix" style="left:87px">
                                            审核人
                                        </div>
                                        <div style="width:220px;left:82px">
                                            <input style="width:220px" type="text" id="departmentNamed" value="" lay-verify="required" placeholder="请输入审核人" lay-reqtext="请填写审核人" autocomplete="off" class="layui-input" lay-affix="clear">
                                        </div>
                                        <div style="left:82px">
                                            <button type="button" class="layui-btn layui-btn-primary" lay-on="test-page-customs">
                                                <i class="layui-icon layui-icon-search"></i>
                                            </button>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-group">
                                        <div class="layui-input-prefix" style="left:55px">
                                            备注
                                        </div>
                                        <div style="width:780px;left:55px">
                                            <textarea style="width:780px" type="textarea" id="productionWorkRemark" value="" lay-verify="required" placeholder="请输入内容" lay-reqtext="请填写备注" autocomplete="off" class="layui-input layui-textarea" lay-affix="clear"></textarea>
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item" style="left:755px">
                                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="demo-Add">保存</button>
                                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                </div>
                            </div>
                            </div>
                        </form>
                        `,
                        success: function () {
                            $(function () {
                                ProductionTypes();
                            })
                            //生产报工类型
                            function ProductionTypes() {
                                $.ajax({
                                    url: '@ViewBag.FoundationRead' + "/api/UserLi/SearchProductionType",
                                    data: JSON.stringify({}),
                                    type: "post",
                                    async: false,
                                    dataType: "json",
                                    contentType: "application/json",
                                    success: res => {
                                        console.log(res.data);
                                        $.each(res.data, function () {
                                            $("#productionTypeIds").append(`<option value="${this.productionTypeId}">${this.productionTypeName}</option>`);
                                        });
                                        form.render('select');//重新渲染下拉框
                                    }
                                })
                            }
                            form.on('input-affix(number)', function (data) {
                                var elem = data.elem; // 输入框
                                var value = elem.value; // 输入框的值 // 获取输入框 DOM 对象
                                $("#productionWorkNum").val(value);
                                form.render();
                                console.log(value); // 当前触发点缀事件的图标元素
                            });

                            // 对弹层中的表单进行初始化渲染
                            form.render();
                            // 表单提交事件
                            form.on('submit(demo-Add)', function (data) {
                                var field = data.field; // 获取表单字段值

                                //获取name数据
                                let first = {
                                    productionWorkNo: $("#productionWorkNo").val(),
                                    productionTypeId: $("#productionTypeIds").val(),
                                    productionWorkOrdersID: localStorage.getItem("productionWorkOrdersID"),
                                    pickingNode: $("#pickingNode").val(),
                                    productionWorkNum: $("#productionWorkNum").val(),
                                    departmentId: localStorage.getItem("departmentid"),
                                    productionWorkTime: $("#productionWorkTime").val(),
                                    productionStart: 0,
                                    productionWorkRemark: $("#productionWorkRemark").val(),
                                    productionWorkState: 0,
                                };
                                console.log("##!!!");
                                // 显示填写结果，仅作演示用
                                // layer.alert(JSON.stringify(field), {
                                //     title: '当前填写的字段值'
                                // });
                                // 此处可执行 Ajax 等操作
                                // …
                                $.ajax({
                                    url: '@ViewBag.FoundationWrite' + "/api/UserLi/CreateProduction",
                                    data: JSON.stringify(first),
                                    type: "post",
                                    async: true,
                                    dataType: "json",
                                    contentType: "application/json",
                                    success: res => {
                                        if (res.code > 0) {
                                            alert('新增成功');
                                            layer.closeAll(); // 关闭当前弹层
                                        }
                                        else {
                                            alert('新增失败');
                                        }
                                    }
                                })
                                return false; // 阻止默认 form 跳转
                            });
                        }
                    });
                }
            })
        });
        //自动生成编码
        function nodeAlls() {
            var datec = new Date()
            var year = datec.getFullYear();
            var month = (datec.getMonth() + 1).toString().padStart(2, "0")
            var date = (datec.getDate() + 1).toString().padStart(2, "0")
            var hours = datec.getHours()
            var minute = (datec.getMinutes()).toString().padStart(2, "0")
            var seconds = (datec.getSeconds()).toString().padStart(2, "0")
            // var Encoding = "IF";
            var result = "IF" + year + month + date + hours + minute + seconds;
            console.log(result);
            $("#productionWorkNo").val(result);

            //重新渲染表单
            form.render();
        }
    </script>
</body>
</html>

<script>
    //文档就绪函数
    $(function () {
        ProductionSearch(1, 2);
        ProductionType();
    })
    var table = layui.table;
    var $ = layui.$;
    var form = layui.form;
    var laydate = layui.laydate;
    var util = layui.util;
    var layer = layui.layer;
    var laypage = layui.laypage;
    //生产报工类型
    function ProductionType() {
        $.ajax({
            url: '@ViewBag.FoundationRead' + "/api/UserLi/SearchProductionType",
            data: JSON.stringify({}),
            type: "post",
            async: false,
            dataType: "json",
            contentType: "application/json",
            success: res => {
                console.log(res.data);
                $.each(res.data, function () {
                    $("#productionTypeId").append(`<option value="${this.productionTypeId}">${this.productionTypeName}</option>`);
                });
                form.render('select');//重新渲染下拉框
            }
        })
    }

    //生产报工列表
    function ProductionSearch(pageIndex, pageSize) {
        let obj = {
            productionTypeId: $('#productionTypeId').val() || -1,
            workStationName: $('#workStationName').val() || "",
            productionWorkOrdersNo: $('#productionWorkOrdersNo').val() || "",
            productManageNode: $('#productManageNode').val() || "",
            productManageName: $('#productManageName').val() || "",
            departmentName: $('#departmentName').val() || "",
            productionStart: $('#sellStockStart').val() || -1,
            pageIndex: pageIndex,
            pageSize: pageSize
        }
        var inst = table.render({
            elem: '#ID-table-demo-datas',
            method: 'post',
            contentType: 'application/json',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', { // 右上角工具图标
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips',
                onClick: function (obj) { // 2.9.12+
                    layer.alert('自定义工具栏图标按钮');
                }
            }],
            url: '@ViewBag.FoundationRead' + '/api/UserLi/SearchProduction',
            where: obj,
            cols: [[
                { field: 'productionTypeName', title: '报工类型', width: 120 },
                { field: 'workStationName', title: '工作站', width: 120 },
                { field: 'productionWorkOrdersNo', title: '生产工单编号', width: 120 },
                { field: 'productManageNode', title: '产品物料编码', width: 120 },
                { field: 'productManageName', title: '产品物料名称', width: 120 },
                { field: 'productManageNumber', title: '规格型号', width: 120 },
                { field: 'productionWorkNum', title: '报工数量', width: 80 },
                { field: 'departmentName', title: '报工人', width: 120 },
                { field: 'productionWorkTimes', title: '报工时间', width: 120 },
                { field: 'departmentName', title: '审核人', width: 120 },
                { field: 'productionStart', title: '状态', width: 120 },
                { fixed: 'right', title: '操作', width: 140, minWidth: 140, templet: '#toolDemos' }
            ]],
            page: false,
            height: 310,
            done: function (res) {
                var id = this.id;
                console.log(res);// 你可以在这里检查返回的数据结构是否符合预期
                // 触发单元格工具事件
                //分页数据
                laypage.render({
                    elem: 'demo-laypage-alles', // 元素 id
                    count: res.totalCount, // 数据总数
                    curr: pageIndex,
                    limit: pageSize,
                    limits: [2, 3, 4],
                    layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'], // 功能布局
                    jump: function (obj, first) {
                        if (!first) {
                            ProductionSearch(obj.curr, obj.limit);
                        }
                    }
                });
            }
        })
    }
    table.on('tool(ID-table-demo-datas)', function (obj) { // 双击 toolDouble
        var data = obj.data; // 获得当前行数据
        //逻辑删除
        if (obj.event === 'delect') {
            //删除前友好提示
            if (confirm("确定删除吗?")) {
                var data = {
                    productionWorkId: data.productionWorkId
                };
                $.ajax({
                    url: '@ViewBag.FoundationWrite' + "/api/UserLi/DeleteProduction",
                    data: JSON.stringify(data),
                    type: 'post',
                    async: false,
                    dataType: 'json',
                    contentType: 'application/json',
                    success: res => {
                        if (res.code > 0) {
                            alert("删除成功");
                            location.reload();
                        }
                        else {
                            alert("删除失败");
                        }
                    }
                });
            }
        }
        //编辑
        else if (obj.event === 'Update') {
            localStorage['productionWorkId'] = data.productionWorkId;
            layer.open({
                type: 2,
                title: '生产报工修改',
                shadeClose: true,
                maxmin: true, //开启最大化最小化按钮
                area: ['1200px', '600px'],
                content: '/Production/ProductionWorkUpdate',
            });
        }
        //审批
        else if (obj.event === 'YesNo') {
            let first = {
                productionWorkId:data.productionWorkId,
                productionStart: 0,
            };
            
            if(data.productionWorkState==0){
                first.productionStart = 1;
            }
            if (data.productionWorkState == 1) {
                first.productionStart = 2;
            }
            if (data.productionWorkState == 2) {
                first.productionStart = 3;
            }
            if (data.productionWorkState == 3) {
                first.productionStart = 4;
            }
            console.log(first);
            $.ajax({
                url: '@ViewBag.FoundationWrite' + "/api/UserLi/UpdProduction",
                data: JSON.stringify(first),
                type: "post",
                async: true,
                dataType: "json",
                contentType: "application/json",
                success: res => {
                    if (res.code > 0) {
                        alert('修改成功');
                    }
                    else {
                        alert('修改失败');
                    }
                }

            })
        }
    });
</script>

<script>
    layui.use(function () {
        var upload = layui.upload;
        var layer = layui.layer;
        // 渲染
        upload.render({
            elem: '.demo-class-accept', // 绑定多个元素
            url: '@ViewBag.FoundationWrite' + "/api/UserLi/ImportPurchaseStorage", // 此处配置你自己的上传接口即可
            accept: 'file', // 普通文件
            done: function (res) {
                layer.msg('上传成功');
                console.log(res);
            }
        });
    });
</script>